package org.datacoder.geocoding.datastructures.util

import org.datacoder.geocoding.datastructures.geoshapes.*

class GeoRectangleStartPointComparator implements Comparator<GeoRectangle> {

    int type

    public GeoRectangleStartPointComparator(int type){
        this.type = type
    }

    public int compare(GeoRectangle gr1, GeoRectangle gr2){
        double returnVal
        returnVal = gr1.retrieveMinValue(type) - gr2.retrieveMinValue(type)
        if(returnVal == 0){
            returnVal = gr1.retrieveMaxValue(type) - gr2.retrieveMaxValue(type)
            if(returnVal == 0){
                returnVal = gr1.juris.id - gr2.juris.id
            }
        }
        if(returnVal == 0){
            return 0
        }
        return ((returnVal > 0) ? 1 : -1)
    }

}

